package com.xiaozou.dao;

import com.mongodb.client.MongoClient;
import com.xiaozou.dao.entity.DoubaoResultRecordEntity;
import lombok.RequiredArgsConstructor;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import javax.annotation.PreDestroy;
import java.util.List;

@Service
@RequiredArgsConstructor
public class QwenRecordDaoService {

    private final MongoTemplate mongoTemplate;
    private final MongoClient mongoClient;

    @PreDestroy
    public void destroy() {
        if (mongoClient != null) {
            mongoClient.close();
        }
    }



//    @PostConstruct
//    public void init() {
//        MongoClientSettings settings = MongoClientSettings.builder()
//                .applyConnectionString(new ConnectionString(uri))
//                .applyToConnectionPoolSettings(builder -> builder.maxSize(3))
//                .build();
//        MongoClient mongoClient = MongoClients.create(settings);
//        mongoTemplate = new MongoTemplate(mongoClient, "qwen");
//    }


    public void save(DoubaoResultRecordEntity doubaoResultRecordEntity) {
        mongoTemplate.save(doubaoResultRecordEntity);
    }


    public List<DoubaoResultRecordEntity> list(String industryCode, String askMethodName,String recognizePoint) {
        return mongoTemplate.find(Query.query(Criteria.where("industryCode").is(industryCode)
                .and("askMethodName").is(askMethodName).and("recognizePoint").is(recognizePoint)).limit(100), DoubaoResultRecordEntity.class
        );
    }
}
